Skip to content

[SYCL][NFC] Extract specialization constant's processing from sycl-post-link to SYCLPostLink library. #19022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from

Conversation

maksimsab
Copy link
Contributor

This change allows later reuse of specialization constant's processing in the New Offloading Model and sycl-jit.

…st-link to SYCLPostLink library.

This change allows later reuse in the New Offloading Model and sycl-jit.
@maksimsab maksimsab requested a review from a team as a code owner June 17, 2025 12:25
@maksimsab
Copy link
Contributor Author

The interface of a functionhandleSpecializationConstants is controversial. It allows to invoke the function in the following manner if you don't need to generate new modules with spec constants replaced by default values:

SmallVector<ModuleDesc> MDs;
Modified |= handleSpecializationConstants(MDs, Mode);

If you have a better alternative for the function's interface let me know.

Copy link
Contributor

@maarquitos14 maarquitos14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, just a few nits.

std::optional<SpecConstantsPass::HandlingMode> Mode,
bool GenerateModuleDescWithDefaultSpecConsts,
SmallVectorImpl<module_split::ModuleDesc> *NewModuleDescs) {
assert((GenerateModuleDescWithDefaultSpecConsts ^ !NewModuleDescs) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite difficult to read. Could we rewrite this to something simpler?
Maybe something like:

Suggested change
assert((GenerateModuleDescWithDefaultSpecConsts ^ !NewModuleDescs) &&
#ifdef NDEBUG
if (GenerateModuleDescWithDefaultSpecConsts)
assert(NewModuleDescs);
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it look to you now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks much better, thanks!!


Modified |= processSpecConstants(MMs[I]);
}
Modified |= handleSpecializationConstants(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of nits:

  1. Rename func as processSpecConsts
  2. The fourth argument can be &MMsWithDefaultSpecConsts and the selection can happen inside processSpecConsts

Comment on lines +8 to +9
// Specialization constants processing consists of lowering and generation
// of new module with spec consts replaced by default values.
Copy link
Contributor

@asudarsa asudarsa Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Specialization constants processing consists of lowering and generation
// of new module with spec consts replaced by default values.
// This file handles processing of metadata and intrinsics related to SYCL specialization constants and generates a
// new module with specialization constants replaced by default values.

namespace llvm {
namespace sycl {

/// Handling consists of SpecConsts's lowering depending on the given
Copy link
Contributor

@asudarsa asudarsa Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Handling consists of SpecConsts's lowering depending on the given
/// Metadata and intrinsics related to SYCL specialization constants are lowered depending on the given

MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
RunSpecConst.addPass(std::move(SCP));

// Perform the spec constant intrinsics transformation on resulting module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Perform the spec constant intrinsics transformation on resulting module.
// Perform the specialization constant intrinsics transformation on resulting module.

}

/// Function generates the copy of the given \p MD where all uses of
/// Specialization Constants are replaced by corresponding default values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Specialization Constants are replaced by corresponding default values.
/// specialization constants are replaced by corresponding default values.

PreservedAnalyses Res = MPM.run(NewMD->getModule(), MAM);
NewMD->Props.SpecConstsMet = !Res.areAllPreserved();
assert(NewMD->Props.SpecConstsMet &&
"This property should be true since the presence of SpecConsts "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reword the error to be more precise?

Suggested change
"This property should be true since the presence of SpecConsts "
"SpecConstsMet should be true since the presence of SpecConsts "

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Minor changes requested.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants